<?php

namespace app\admin\model\book;

use app\admin\model\Book;
use think\Model;


class Files extends Model
{

    

    

    // 表名
    protected $name = 'book_files';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
	protected $updateTime = false;

    // 追加属性
    protected $append = ['fullurl', 'imagetype'];

	/**
     * 创建者
     */
    public function admin()
    {
        return $this->belongsTo("\\app\\admin\\model\\Admin", 'admin_id');
    }

    /**
     * 关联教材
     */
    public function book()
    {
        return $this->belongsTo(Book::class, 'book_id');
    }

    /**
     * 关联单元
     */
    public function unit()
    {
        return $this->belongsTo(Unit::class, 'book_id');
    }

	public function getFullurlAttr($value, $data){
		return cdnurl($data['url'], true);
	}

	public function getImagetypeAttr($value, $data){
		return pathinfo($data['url'], PATHINFO_EXTENSION);
	}

}
